<template>
  <div class="app-container" v-if="show">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="统计月份" prop="monthly">
        <!-- <el-date-picker
          key="daterange"
          v-model="rangeDate"
          type="daterange"
          value-format="yyyy-MM-dd HH:mm:ss"
          :picker-options="{
            disabledDate: (time) =>
              !(
                time.getTime() >= Date.now() - 365 * 8.64e7 &&
                time.getTime() < Date.now() - 8.64e7
              ),
          }"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          style="width: 240px"
          @change="handleChange"
          size="mini"
        /> -->
        <el-date-picker
          type="month"
          @change="changeTime"
          v-model="queryParams.monthly"
          placeholder="选择月"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="品牌" prop="brandName">
        <!-- <el-input
          v-model="queryParams.brand"
          placeholder="请输入品牌"
          clearable
          @keyup.enter.native="handleQuery"
        /> -->
        <el-select
          v-model="queryParams.brand"
          placeholder="选择品牌"
          clearable
          filterable
        >
          <el-option
            v-for="dict in dict.type.sys_product_pp"
            :key="dict.value"
            :label="dict.label"
            :value="dict.label"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="供应商" prop="supplier">
        <!-- <el-input
          v-model="queryParams.supplier"
          placeholder="选择供应商"
          clearable
          @keyup.enter.native="handleQuery"
        /> -->
        <el-select
          v-model="queryParams.supplier"
          placeholder="选择供应商"
          clearable
          filterable
        >
          <el-option
            v-for="dict in dict.type.sys_product_coder"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="一级类目" prop="firstLevelColumnList">
        <el-select
          v-model="queryParams.firstLevelColumnList"
          placeholder="请选择一级类目"
          multiple
          clearable
        >
          <el-option
            v-for="dict in dict.type.sys_product_pl"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="合同号" prop="contractNumber">
        <el-input
          v-model="queryParams.contractNumber"
          placeholder="请输入合同号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item class="flex_one tr">
        <el-button
          icon="el-icon-search"
          size="mini"
          type="primary"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <!-- <el-form
      class="ry_form"
      v-show="showSearch"
      :inline="true"
      label-width="100px"
      :model="queryParams"
      ref="queryForm"
      size="medium"
    >
      <el-form-item label="类型" prop="panelType">
        <DictRadio
          v-model="queryParams.panelType"
          :radioData="dict.type.wms_inventory_panel_type"
          size="small"
          @change="handleQuery"
        ></DictRadio>
      </el-form-item>
      <el-form-item label="物料" prop="itemId">
        <item-select v-model="queryParams.itemId"></item-select>
      </el-form-item>
      <el-form-item label="仓库" prop="rackId">
        <wms-warehouse-cascader
          v-model="queryParams.place"
        ></wms-warehouse-cascader>
      </el-form-item>
      <el-form-item label="库存" prop="quantity">
        <number-range v-model="queryParams.quantityRange"></number-range>
      </el-form-item>
      <el-form-item class="flex_one tr">
        <el-button
          icon="el-icon-search"
          size="mini"
          type="primary"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form> -->
    <el-row class="mb8" :gutter="10">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          >导出
        </el-button>
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-table
      :data="wmsInventoryList"
      @selection-change="handleSelectionChange"
      :height="630"
      border
      :header-cell-style="{ background: '#027db4', color: '#fff' }"
    >
      <el-table-column label="品牌" align="center" prop="brand" />
      <el-table-column label="退货发生月份" align="center" prop="monthly">
      </el-table-column>
      <el-table-column label="供应商" align="center" prop="supplier" />
      <el-table-column label="skc" align="center" prop="skc" />
      <el-table-column label="产品款号" align="center" prop="spu" />
      <el-table-column label="颜色" align="center" prop="colorProperty" />
      <el-table-column label="退货件数" align="center" prop="returnQuantity">
        <!-- <template slot-scope="scope">
          <div
            style="
              color: rgb(37, 137, 255);
              cursor: pointer;
              text-decoration: underline;
            "
            @click="handlereturnQuantity(scope.row)"
          >
            {{ scope.row.returnQuantity }}
          </div>
        </template> -->
      </el-table-column>
      <el-table-column label="退货成本价" align="center" prop="unitPrice" />
      <el-table-column label="退回总金额" align="center" prop="totalAmount" />
      <!-- <el-table-column
        label="下单金额占比(占月度总额)"
        align="center"
        prop="orderAmountMonthRatio"
      />
      <el-table-column
        label="下单数量占比(占月度总额)"
        align="center"
        prop="orderQuantityMonthRatio"
      />
      <el-table-column
        label="下单金额占比(占年度总额)"
        align="center"
        prop="orderAmountYearRatio"
      />
      <el-table-column
        label="下单数量占比(占年度总额)"
        align="center"
        prop="orderQuantityYearRatio"
      />

      <el-table-column
        label="超期30天未入库数量"
        align="center"
        prop="overdueQuantity30Days"
      />
      <el-table-column
        label="超入数量"
        align="center"
        prop="overOrderQuantity"
      /> -->
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="pageList"
    />
  </div>
</template>

<script>
import moment from "moment";
import {
  listPurchaseBasicsDwd,
  getPurchaseBasicsDwd,
  delPurchaseBasicsDwd,
  addPurchaseBasicsDwd,
  updatePurchaseBasicsDwd,
  synData,
  selectConditionList,
  selectPurchaseMonth,
  selectPurchaseReturnVoList,
} from "@/api/purchase/PurchaseReturn";
// import { listWmsInventory, exportWmsInventory } from "@/api/wms/inventory";
// import NumberRange from "@/components/NumberRange";
// import ItemSelect from "@/components/ItemSelect";
import PanelByItem from "@/views/purchase/inventory/component/PanelByItem.vue";
import PanelByItemType from "@/views/purchase/inventory/component/PanelByItemType.vue";
import PanelByWarehouse from "@/views/purchase/inventory/component/PanelByWarehouse.vue";
import PanelByArea from "@/views/purchase/inventory/component/PanelByArea.vue";
// import { isStarRepo } from "@/utils/is-star-plugin";
// import { mapGetters } from "vuex";
import { listBrandChannelShop, listAll } from "@/api/chart/brandChannelShop";
export default {
  name: "WmsInventory",
  dicts: [
    "sys_product_qudao",
    "sys_one_zero",
    "sys_product_size",
    "sys_sample_sf",
    "sys_jst_sample_sf",
    "sys_product_pp",
    "sys_product_coder",
    "sys_product_pl",
  ],
  components: {
    PanelByArea,
    PanelByWarehouse,
    PanelByItemType,
    PanelByItem,
    // ItemSelect,
    // NumberRange,
  },
  // dicts: ["wms_inventory_panel_type"],
  data() {
    return {
      //   queryParams.: "",
      rangeDate: [],
      show: true,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 库存表格数据
      wmsInventoryList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        dataDate: null,
        brandName: null,
        supplier: null,
        contractNumber: null,
        sku: null,
        purchaseOrderNumber: null,
        isNewProduct: null,
        orderQuantity: null,
        contractPurchasePrice: null,
        contractAmount: null,
        isTaxIncluded: null,
        additionalCostPerUnit: null,
        orderAdditionalCost: null,
        additionalCostDescription: null,
        costPriceIncludingTax: null,
        costPriceExcludingTax: null,
        taxAmountPerUnit: null,
        contractDeliveryDate: null,
        quantityReceived: null,
        isOverdue30Days: null,
        overdueQuantity30Days: null,
        isOverOrder: null,
        overOrderQuantity: null,
        remarks: null,
        dataYear: null,
        dataMonth: null,
        startTime: null,
        endTime: null,
        // contractType: "产品",
        monthly: "",
      },
      pageReq: {
        page: 1,
        size: 10,
      },
      // 表单参数
      form: {},
      columns: [],
      panelType: 5,
    };
  },
  created() {
    // const res = await isStarRepo(
    //   "zccbbg",
    //   "RuoYi-Mall",
    //   this.userId,
    //   "http://wms.ichengle.top/inventory",
    //   "ruoyi-mall-商城",
    //   "https://gitee.com/zccbbg/RuoYi-Mall"
    // );
    // this.show = res;
    // if (res) {
    //   this.getList();
    // }

    let date = new Date(new Date() - 30 * 24 * 3600 * 1000);

    this.queryParams.monthly = moment(date).format("YYYY.MM");
    this.getList();
  },
  //   computed: {
  //     // ...mapGetters(["userId"]),
  //     currentComponent() {
  //       console.log(this.panelType);
  //       let type = parseInt(this.panelType);
  //       switch (type) {
  //         case 5:
  //           return "panel-by-warehouse";
  //         case 10:
  //           return "panel-by-area";
  //         case 20:
  //           return "panel-by-item-type";
  //         default:
  //           return "";
  //       }
  //     },
  //   },
  methods: {
    changeTime() {
      this.queryParams.monthly = moment(this.queryParams.monthly).format(
        "YYYY.MM"
      );
      if (this.queryParams.monthly == "Invalid date") {
        this.queryParams.monthly = "";
      }
      this.getList();
      console.log(JSON.stringify(this.queryParams.monthly));
    },
    handleChange() {
      this.queryParams.startTime = this.rangeDate[0];
      this.queryParams.endTime = this.rangeDate[1];
      this.getList();
    },
    pageList() {
      selectPurchaseReturnVoList(this.queryParams).then((response) => {
        this.wmsInventoryList = response.rows ? response.rows : [];
        this.total = response.total;
      });
    },
    /** 查询库存列表 */
    getList() {
      console.log(111);
      selectPurchaseReturnVoList(this.queryParams).then((response) => {
        this.wmsInventoryList = response.rows ? response.rows : [];
        this.total = response.total;
      });
    },

    // 表单重置
    reset() {
      this.form = {
        id: null,
        itemId: null,
        rackId: null,
        quantity: null,
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      // this.pageReq.page = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams = {};
      this.handleQuery();
      // this.queryParams.brand = "";
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "purchase/PurchaseReturn/exportPurchaseReturnVo",
        {
          ...this.queryParams,
        },
        `exportPurchaseReturnVo${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
/**下单月份*/
@Excel(name = "下单月份")
private String monthly;

/** 品牌 */
@Excel(name = "品牌")
private String brand;

/** 供应商 */
@Excel(name = "供应商")
private String supplier;

/** 下单合同数 */
@Excel(name = "下单合同数")
private Integer orderContractQuantity;


/** 下单skc种类数 */
@Excel(name = "下单skc种类数")
private Integer orderSkcQuantity;

/** 下单产品总数 */
@Excel(name = "下单产品总数")
private Integer orderProQuantity;

/** 待入库产品数 */
@Excel(name = "待入库产品数")
private Integer waitProQuantity;

/** 下单金额占比(占月度总额) */
@Excel(name = "下单金额占比(占月度总额)")
private Double orderAmountMonthRatio;

/** 下单数量占比(占月度总额) */
@Excel(name = "下单数量占比(占月度总额)")
private Double orderQuantityMonthRatio;

/** 下单金额占比(占年度总额) */
@Excel(name = "下单金额占比(占年度总额)")
private Double orderAmountYearRatio;

/** 下单数量占比(占年度总额) */
@Excel(name = "下单数量占比(占年度总额)")
private Double orderQuantityYearRatio;

/** 产品类型 */
private String contractType;



/** 合同采购金额（¥） */
@Excel(name = "合同金额", readConverterExp = "¥=")
private Double contractAmount;


/** 已入库数量 */
@Excel(name = "已入库数量")
private Integer quantityReceived;

/** 协议日期内已交货数量 */
@Excel(name = "协议日期内已交货数量")
private Integer overdueQuantity30Days;

/** 超入数量 */
@Excel(name = "超入数量")
private Integer overOrderQuantity;

